<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增商品的属性(独立)')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-attribute-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">属性名称：</label>
                <div class="col-sm-8">
                    <input name="attrName" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">商品模型：</label>
                <div class="col-sm-8">
                    <select class="form-control" name="typeId" id="selectObj">

                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "shop/attribute"
        $("#form-attribute-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-attribute-add').serialize());
            }
        }

        $(document).ready(function (){
            var options = [];
            var selectObj = $("#selectObj");
            var optionValue = 0;
            var optionName = '';
            var row = null;
            var optionStr = '';
            var config = {
                url: "/shop/type/list",
                type: "post",
                dataType: "json",
                data: {pageSize:100},
                // beforeSend: function () {
                //     $.modal.loading("正在处理中，请稍后...");
                // },
                success: function(data) {
                    for (var i = 0;i < data.total;i++) {
                        row = data.rows[i];
                        optionValue = row.id;
                        optionName = row.name;
                        options.push("<option value="+optionValue+">"+optionName+"</option>");
                    }
                    optionStr = options.join('');

                    selectObj.html(optionStr);
                }
            };
            $.ajax(config)
        })
    </script>
</body>
</html>